import { getActiveCustomizeView } from "@/api/active";
import { generateHash } from "@/utils/hash";
import { defineStore } from "pinia";

// 创建一个名为menu的store 自定义菜单
export const menu = defineStore("menu", {
  state: () => {
    return {
      // 自定义菜单
      customMenu: [],

      userMenuData: [
      // {
      //   id: '1',
      //   name: 'wallet',
      //   lang: 'page.navbar.wallet',
      // },
      {
        id: '2',
        name: 'Transactions1',
        lang: 'page.navbar.Transactions',
      },{
        id: '7',
        name: 'tixian',
        lang: 'layer.wallet.withdrawMoney',
      },{
        id: '3',
        name: 'VIP',
        lang: 'layer.activity.VIP',
      },{
        id: '4',
        name: 'Affiliate',
        lang: 'page.navbar.affiliate',
      },{
        id: '5',
        name: 'Statistics',
        lang: 'page.navbar.statiscation',
      },{
        id: '6',
        name: 'Transactions',
        lang: 'page.navbar.mybet',
      },{
        id: '8',
        name: 'About us',
        lang: 'page.navbar.aboutus',
      },{
        id: '10',
        name: 'setting',
        lang: 'page.navbar.setting',
      },{
        id: '9',
        name: 'Logout',
        lang: 'page.navbar.logout',
      },],
    };
  },
  getters: {
    getCustomeMenu: state => {
      return state.customMenu;
    }
  },
  actions: {
    // 获取自定义菜单
    async getActiveCustomizeViewData() {
      return new Promise((resolve, reject) => {
        getActiveCustomizeView()
          .then(res => {
            console.log("自定义菜单", res);
    
            if (res?.errno === 0) {
              this.customMenu = res.data.list;
              console.log("defineStore自定义菜单", this.customMenu);
              resolve(res.data.list); // 成功时解析 Promise 为 res.data.list
            } else {
              reject(new Error('请求失败，errno: ' + res?.errno)); // 处理错误情况
            }
          })
          .catch(error => {
            reject(error); // 处理网络请求异常
          });
      });
    }
  }
});
